extends Node
var tscnBullet:Resource=preload("res://prefab/bullet.tscn")

func start():
	pass
var _campActorDic:Dictionary={}

func addActorV(actorV):
	var arr=getActorsArr(actorV.actorM.camp,actorV.actorM.regionId)
	if !arr.has(actorV):
		arr.append(actorV)
func removeActorV(actorV):
	var arr=getActorsArr(actorV.actorM.camp,actorV.actorM.regionId)
	arr.erase(actorV)
#返回原始数组
func getActorsArr(camp,regionId):
	if !_campActorDic.has(camp):
		_campActorDic[camp]={}
	if !_campActorDic[camp].has(regionId):
		_campActorDic[camp][regionId]=[]
	return _campActorDic[camp][regionId]

func attack(from,to):
	var place=G.getBattlePlace(from.actorM.regionId)
	if !place:
		return
	var info=DamageInfo.new()
	info.from=from
	info.to=to
	info.dmg=from.actorM.atk
	var bullet=tscnBullet.instance() as Bullet
	bullet.position=info.from.position
	place.add_child(bullet)
	bullet.start(info)

#a 对b造成伤害
func damage(info:DamageInfo):
	#计算防御
	#var from=info.from.actorM
	var toM=info.to.actorM
	#正防御
	if toM.def>0:
		var dr=float(toM.def)/(toM.def+100)
		info.dmg=floor(info.dmg*(1-dr))
	elif toM.def<0: #负防御  防御如果为0 不做处理
		var ir=float(abs(toM.def))/(abs(toM.def)+100)
		info.dmg=floor(info.dmg*(1+ir))
	if info.dmg>0:
		toM.hp-=info.dmg
		info.to.hit_ani()
		G.createJumpNum(str(info.dmg),info.to.actorM.regionId,
			info.to.position+Vector2(rand_range(-10,10),rand_range(-10,10)))
	
#func heal(info:HealInfo):
#	var from=info.from
#	var to=info.to
#	if info.heal<0:
#		info.heal=0
#	return info

func shareExp(enemyV):
	var killExp=enemyV.actorM.killExp
	var arr=getActorsArr(enemyV.actorM.get_oppentCamp(),enemyV.actorM.regionId)
	for actor in arr:
		if actor.actorM.type=='player':
			actor.actorM.experience+=killExp
	pass

